import os
import io
from contextlib import redirect_stdout
from typing import Any
from colorama import Fore
result = True


def testcase(test: "Any", ans: str = None):
    global result
    out = io.StringIO()
    with redirect_stdout(out):
        print(test)
    if ans is None:
        print(out.getvalue(), "", Fore.RED+"FAILED", Fore.RESET)
        result = False
        return False
    else:
        res = ans.strip() == out.getvalue().strip()
        result = result and res
        if res:
            print(out.getvalue(), "", Fore.GREEN+"SUCCESS", Fore.RESET)
        else:
            print(out.getvalue(), "", Fore.RED+"FAILED", Fore.RESET)
        return res


def reset():
    global result
    result = True


def check():
    global result
    if result:
        print(Fore.GREEN+"DONE. SUCCESS", Fore.RESET)
    else:
        print(Fore.RED+"DONE. FAILED", Fore.RESET)
